package com.example.springboot.controller;

import com.example.springboot.document.ResultBo;
import com.example.springboot.exception.PasswordException;
import com.example.springboot.exception.ValidateCodeException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @Description: RestGoodsController
 * @Author wenlinyu
 * @Date: 2020/12/16 15:48
 * @Version 1.0
 */
@RestController
@RequestMapping("/rest")
public class RestGoodsController {

    @GetMapping("/goods")
    public ResultBo goods() {
        return new ResultBo(new ArrayList<>());
    }

    @GetMapping("/checkPassword")
    public ResultBo checkPassword() throws PasswordException {
        if (true) {
            // 模拟抛出异常，便于测试
            throw new PasswordException();
        }
        return new ResultBo(true);
    }

    @GetMapping("/checkValidate")
    public ResultBo checkValidate() throws ValidateCodeException {
        if (true) {
            // 模拟抛出异常，便于测试
            throw new ValidateCodeException();
        }
        return new ResultBo(true);
    }

    @GetMapping("/other")
    public ResultBo other() throws Exception {
        // 模拟异常
        int a = 1 / 0;
        return new ResultBo(true);
    }
}
